package com.xiaoniu.lib_keleim.pojo.dos;


import com.xiaoniu.lib_keleim.pojo.vos.MessageConversationVO;
import com.xiaoniu.lib_keleim.pojo.vos.UserInfoVO;

import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey;


public class ConversationEntity extends RealmObject {

    @PrimaryKey
    public Long conversationId;

    public Long lastMessageId;
    //目标
    public long targetId;
    //发送人用户ID
    public long userId;

    public Long updateTime;

    public Long createTime;

    public MessageEntity messageChatDO;



    public long getRealTargetId() {
        if (UserInfoVO.getSingleton().getCustomerId()==userId) {
            return targetId;
        }
        return userId;
    }


    public MessageConversationVO toMessageConversationVO() {
        MessageConversationVO conversationEntity = new MessageConversationVO();
        conversationEntity.lastMessageId = lastMessageId;
        conversationEntity.targetId = targetId;
        conversationEntity.userId = userId;
        conversationEntity.updateTime = updateTime;
        conversationEntity.createTime = createTime;

        if (messageChatDO!=null) {
            conversationEntity.messageChatVO = messageChatDO.toMessageChatVO();
        }
        return conversationEntity;
    }

    public void generateLocalId() {
        conversationId = getRealTargetId();
    }

    public long getConversationId() {
        return conversationId;
    }
}
